//
//  AppDelegate.m
//  旅游咨询
//
//  Created by 徐斌 on 15/4/13.
//  Copyright (c) 2015年 xubin. All rights reserved.
//

#import "AppDelegate.h"
#import "DataHandle.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
    [self.window makeKeyAndVisible];
    
    
    // 游记
    TravelNotesHomePageViewController *travelVC = [[TravelNotesHomePageViewController alloc]init];
    [_window release];
    UINavigationController *naVC = [[UINavigationController alloc]initWithRootViewController:travelVC];
    naVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"游记" image:[UIImage imageNamed:@"iconfont-zhutiyou-3.png"] tag:1];
    [naVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation.png"] forBarMetrics:UIBarMetricsDefault];
    naVC.tabBarItem.title = @"游记";
    // 国内
    InLandCityViewController *inLandVC = [[InLandCityViewController alloc]init];
    UINavigationController *inLandeNaVC = [[UINavigationController alloc]initWithRootViewController:inLandVC];
    inLandeNaVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"国内游" image:[UIImage imageNamed:@"iconfont-guoneiyou-2.png"] tag:2];
    [inLandeNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation.png"] forBarMetrics:UIBarMetricsDefault];
    
    // 国外
    RootViewController *homeVC = [[RootViewController alloc]init];
    UINavigationController *homeNaVC = [[UINavigationController alloc]initWithRootViewController:homeVC];
    homeNaVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"国外游" image:[UIImage imageNamed:@"iconfont-jingwaiyou-3.png"] tag:3];
    [inLandeNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation.png"] forBarMetrics:UIBarMetricsDefault];
    
    // 更多
    MoreViewController *moreVC = [[MoreViewController alloc]init];
    UINavigationController *moreNaVC = [[UINavigationController alloc]initWithRootViewController:moreVC];
    moreVC.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"更多" image:[UIImage imageNamed:@"iconfont-gengduo-6.png"] tag:4];
    [moreNaVC.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigation.png"] forBarMetrics:UIBarMetricsDefault];
    
    
    UITabBarController *tabBar = [[UITabBarController alloc]init];
    self.window.rootViewController = tabBar;
    tabBar.delegate = self;
    tabBar.viewControllers = [NSArray arrayWithObjects:naVC, inLandeNaVC, homeNaVC, moreNaVC, nil];
    [[DataHandle sharDataBaseHandle]openDB];

//    [self showIntroWithCrossDissolve];

    NSUserDefaults * settings1 = [NSUserDefaults standardUserDefaults];
    NSString *key1 = [NSString stringWithFormat:@"is_first"];
    NSString *value = [settings1 objectForKey:key1];
    if (!value)
    {
        [self showIntroWithCrossDissolve];
        NSUserDefaults * setting = [NSUserDefaults standardUserDefaults];
        NSString * key = [NSString stringWithFormat:@"is_first"];
        [setting setObject:[NSString stringWithFormat:@"false"] forKey:key];
        [setting synchronize];
    }
    
    
    
    
    return YES;
}
//- (void)viewDidAppear:(BOOL)animated {
//    [self showIntroWithCrossDissolve];
//
//}

- (void)showIntroWithCrossDissolve {
    EAIntroPage *page1 = [EAIntroPage page];
    page1.title = @"途,吃喝玩乐";
    page1.titleFont = [UIFont systemFontOfSize:24];
    //    page1.desc = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
    page1.bgImage = [UIImage imageNamed:@"11_meitu_2.png"];
    //    page1.titleImage = [UIImage imageNamed:@"original"];
    //    53821def2d09540172cc8f98420591b3.jpg
    //    ab948bd0641f084361fb93064e5c87b2.jpg
    //    53821def2d09540172cc8f98420591b3_meitu_11.png
    //    ab948bd0641f084361fb93064e5c87b2_meitu_10.png
    EAIntroPage *page2 = [EAIntroPage page];
    page2.title = @"景,钟灵毓秀";
    page2.titleFont = [UIFont systemFontOfSize:24];
    
    //    page2.desc = @"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore.";
    page2.bgImage = [UIImage imageNamed:@"22_meitu_3.png"];
    //    page2.titleImage = [UIImage imageNamed:@"supportcat"];
    
    EAIntroPage *page3 = [EAIntroPage page];
    page3.title = @"一场说走就走的旅行";
    page3.titleFont = [UIFont systemFontOfSize:24];
    
    //    page3.desc = @"Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.";
    page3.bgImage = [UIImage imageNamed:@"b2cb7c396463e847b5450504bc272c80_meitu_12.png"];
    //    page3.titleImage = [UIImage imageNamed:@"femalecodertocat"];
    
    
    EAIntroPage *page4 = [EAIntroPage page];
    page4.title = @"景途,比您想的更多";
    page4.titleFont = [UIFont systemFontOfSize:24];
    //    page4.desc = @"Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.";
    page4.bgImage = [UIImage imageNamed:@"53821def2d09540172cc8f98420591b3_meitu_11.png"];
    //    page4.titleImage = [UIImage imageNamed:@"femalecodertocat"];
    
    EAIntroView *intro = [[EAIntroView alloc] initWithFrame:self.window.bounds andPages:@[page1,page2,page3,page4]];
    
    [intro setDelegate:self];
    [intro showInView:self.window animateDuration:0.0];
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
